#ifndef VIDEO_H_
# define VIDEO_H_

# include <libavcodec/avcodec.h>
# include <libavformat/avformat.h>
# include <libswscale/swscale.h>
# include "sound_output.h"
# include <stdio.h>
# include <string.h>
# include <ncurses.h>
# include "caml.h"
# include "sound_output.h"

# define DEFAULT_AV_SYNC_TYPE  AV_SYNC_VIDEO_MASTER


/* #define BUFSIZE AVCODEC_MAX_AUDIO_FRAME_SIZE */

typedef			struct PacketQueue
{
  AVPacketList		*first_pkt;
  AVPacketList		*last_pkt;
  int			nb_packets;
  int			size;

}			PacketQueue;


typedef			struct _video
{
  struct SwsContext	*Sctx;

  AVFormatContext	*pFormatCtx;
  AVCodecContext	*pCtx;
  AVCodecContext	*pAudioCodec;

  AVCodec		*pCodec;
  AVCodec		*pAudio;

  AVFrame		*pRaw;
  AVFrame		*pDat;
  uint8_t		*buffer;

  pa_simple		*pass;

  int			videoStream;
  int			width;
  int			height;
  int			format;
  int			fluxAudio;

  int			seek_req;
  int			seek_flags;
  int64_t		seek_pos;


  /* unsigned_int		audio_clock; */
  int64_t		video_current_pts_time;
  int			av_sync_type;
  /* unsigned_ */int		audio_buf_size;
}			video;


video			*video_init(value		fichier);


/*
 * Parse next packet from cur video
 * Returns 0 on succes
 * -1 on read error,
 * -2 when not a video packet (ignore these)
 * -3 for invalid frames (skip these)
 */
value			video_next(video		*cur);

value			end_curse(value			unused);

value			video_quit(video		*cur);

value			video_debug_ppm(value		cur,
					value		file);

value			width(video			*cur);

value			height(video			*cur);

value			pixel(video			*current,
			      value			i,
			      value			j);

value			addchar(value			str,
				value			x,
				value			y);

value			curse_aff(value			str,
				  value			colored,
				  value			col);

value			end_curse(value			unused);

value			refr(value			unused);

value			mv_init(value			unused);


void stream_seek(video *is, int64_t pos, int rel);

/* int			th_video(video			*current); */

#endif
